package com.zkhz.base.security.util;

import com.google.common.collect.Sets;
import com.zkhz.base.util.system.SpringBeansUtil;
import org.springframework.core.env.Environment;

import java.util.Set;

/**
 * 判断是否超级管理员，修改配置不需要重启应用
 *
 * @author wuzeqin
 * @date 2021/8/11
 **/
public class SuperAdminUtil {

    public static boolean isSuperAdmin(String userId) {
        return getSuperAdmins().contains(userId);
    }

    @SuppressWarnings("unchecked")
    public static Set<String> getSuperAdmins() {
        Environment environment = SpringBeansUtil.getBean(Environment.class);
        Set<String> set = environment.getProperty("super-admin-ids", Set.class);
        return set != null ? set : Sets.newHashSet("admin", "system");
    }

}
